// The class that controls ships.

#ifndef SHIP_OBJECT_HPP
#define SHIP_OBJECT_HPP

#include <Ogre.h>

// Special #define used to allow the use of putting anything into the UserData
// section of a Newton Body.
#define OGRENEWT_NO_OGRE_ANY
#include <OgreNewt.h>

#include "ShipInput.hpp"

class ShipTemplate
{
	public:
		std::string sShipName;
		std::string sMeshName;
		float fMass;
		float fLinearDrag;		
		float fForwardThrust;
		float fReverseFraction;
		Ogre::Vector3 fAngularDrag;
		Ogre::Vector3 fSteeringThrust;
};

class ShipHardpoint
{
	public:
		std::string sHardpointName;
		Ogre::SceneNode* pAttachedNode;
};

class ShipObject
{
	public:

		ShipObject();
		~ShipObject();

		void spawnNewShip(Ogre::SceneManager* i_pSceneMgr, std::string i_sShipName, ShipTemplate* i_pShipTemplate,
								OgreNewt::World* i_pPhysWorld,
								ShipInput* i_pShipInputSource = 0,
								Ogre::Vector3 i_StartPosition = Ogre::Vector3::ZERO, 
								Ogre::Quaternion i_StartOrientation = Ogre::Quaternion::IDENTITY);

		// The update cycle where the ship will compute its movements.
		void updateShip(double timeSinceLastFrame);

		// Set where the input is going to be coming from.
		void setShipInputSource(ShipInput* i_pShipInputSource);

		// Getter functions for various ship properties.
		ShipInput* getShipInputSource();
		ShipObject* getShipPointer();
		Ogre::SceneNode* getShipSceneNode();
		std::string getShipName();
		ShipTemplate* getShipTemplate();

	private:

		// Keep track of ones own Ogre stuff.
		Ogre::SceneNode* m_pShipSceneNode;
		Ogre::Entity* m_pShipEntityModel;

		// Pointer to the PhysWorld being used.
		OgreNewt::World* m_pPhysWorld;

		// Keep track of ones own Physics stuff.
		OgreNewt::Body* m_pShipBody;
		OgreNewt::CollisionPrimitives::ConvexHull* m_pShipCol;
		
		// Position and orientation.
		void applyShipForces(OgreNewt::Body* ShipBody, float timeSinceLastFrame, int nThreadIndex);

		// Pointer to where we get our input information from.
		ShipInput* m_pShipInputSource;

		// Pointer to the ship template used to create this ship.
		ShipTemplate* m_pShipTemplate;

		// Populate ship hardpoints.
		void populateShipHardpoints();

		// The actual vector which holds all the ship hardpoints.
		

		// Billboards used for prototype lights.
		Ogre::BillboardSet* m_pBillboardSet;
		Ogre::Billboard* m_pWhiteLight;
};

#endif